/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 25228
 * Date: 2024-08-01
 * Time: 15:40
 */
public class Solution {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        int lenl=0;
        int lens=0;
        ListNode curl=headA;
        ListNode curs=headB;
        while(curl.next!=null){
            curl=curl.next;
            lenl++;
        }
        while(curs.next!=null){
            curs=curs.next;
            lens++;
        }
        int len=lenl-lens;
        if(len>0){
            curl=headA;
            curs=headB;
        }else if(len<0){
            len=-len;
            curl=headB;
            curs=headA;
        }if(len==0){
            curl=headA;
            curs=headB;
        }
        for(int i=0;i<len;i++){
            curl=curl.next;
        }
        while(curl!=curs){
            curl=curl.next;
            curs=curs.next;
        }
        return curl;
    }
}
